//
//  UIButton+Extension.swift
//  01-启动图片的搭建
//
//  Created by 白利兵 on 15/10/14.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

extension UIButton{
    // 遍历构造器1
    convenience init(imageName: String, backImageName: String){
        self.init()
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Selected)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Selected)
        sizeToFit()
        
    }
    // 遍历构造器2
    convenience init(title: String, fontSize: CGFloat, color: UIColor, backImageName: String?, backColor: UIColor) {
        
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        backgroundColor = backColor
        if let backImgName = backImageName {
            setBackgroundImage(UIImage(named: backImgName), forState: .Normal)
        }
        sizeToFit()
    }
    // 遍历构造器3
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String?) {
        
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        
        if let imgName = imageName {
            setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        }
        sizeToFit()
    }
}
